#include "commonoptionstablemodel.h"

CommonOptionsTableModel::CommonOptionsTableModel(): opts(QSharedPointer<CommonOptions>()) {}

QVariant CommonOptionsTableModel::data(const QModelIndex& index, int role) const {
    if (!index.isValid()) {
        return QVariant();
    }
    if (role != Qt::DisplayRole) {
        return QVariant();
    }
    switch(index.column()) {
    case 0:
        switch(index.row()) {
        case 0:
            return tr("Exposition");
        case 1:
            return tr("Transition");
        case 2:
            return tr("Ionization voltage");
        case 3:
            return tr("CP");
        case 4:
            return tr("Emission current");
        case 5:
            return tr("Heat current");
        case 6:
            return tr("Focus voltage 1");
        case 7:
            return tr("Focus voltage 2");
        case 8:
            return tr("Custom transition (before)");
        case 9:
            return tr("Custom transition (forward)");
        case 10:
            return tr("Custom transition (backward)");
        }
    case 1:
        if (opts.isNull()) {
            return QVariant();
        }
        switch(index.row()) {
        case 0:
            return opts->eTimeReal();
        case 1:
            return opts->iTimeReal();
        case 2:
            return opts->iVoltageReal();
        case 3:
            return opts->CPReal();
        case 4:
            return opts->eCurrentReal();
        case 5:
            return opts->hCurrentReal();
        case 6:
            return opts->fV1Real();
        case 7:
            return opts->fV2Real();
        case 8:
            return opts->befTimeReal();
        case 9:
            return opts->fTimeReal();
        case 10:
            return opts->bTimeReal();
        }
    }
    return QVariant();
}

void CommonOptionsTableModel::newData(QSharedPointer<CommonOptions> options) {
    opts = options;
    emit dataChanged(index(0, 1), index(10, 1));
}
